﻿/*!	@file	r_rtti_class_base.h
	@brief	型情報取得用クラスの基底
Copyright (c) 2009 Yuya Yamaguchi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef _R_RTTI_CLASS_BASE_H_
#define _R_RTTI_CLASS_BASE_H_

#include "r_rtti_reflection_declare.h"

namespace r{
	namespace rtti{
		//! 基底クラス
		/*! 仮想関数ポインタ分サイズが増えても良いクラスはこのクラスの派生クラスにして下さい。
		リフレクション登録などが素敵になります。
		多重継承は出来ません。
		*/
		class ClassBase
		{
			RRTTI_REFLECTION_DECLARE
		public:
			ClassBase(){}
			virtual ~ClassBase(){}
			r_bool						isExactClass ( const Info	*_RTTI ) const;
			r_bool						isKindOf ( const Info	*_RTTI ) const;
	
		protected:
			//! デシリアライズの後に呼び出されます
			/*! デシリアライズによりパラメータが設定された後で特殊な初期化処理が必要な場合に実体を定義して下さい。
			*/
			virtual void				setupAfterDeserialize( void );
		private:
		};

		// -----------------------------------------------------------

		// シリアライズ定義用アクセス修飾子
		#define	__r_serialize			protected

		// -----------------------------------------------------------
		//! 型情報を利用したキャスト
		template<class S>
		class dynamicCastNonPtr
		{
		public:
			typedef S	type;
		};
		template<class S>
		class dynamicCastNonPtr<S*>
		{
		public:
			typedef S	type;
		};
		template<class T, class N>
		static	T					dynamicCast ( N src )
		{
			if ( src->isKindOf ( typename getRTTI< dynamicCastNonPtr< T >::type >() ) ) {
				return reinterpret_cast<T> ( src );
			}
			return NULL;
		}
	}
}


#endif // _R_RTTI_CLASS_BASE_H_
